package com.it.test;

import java.util.Random;
import java.util.Scanner;

public class test11 {
    public static void main(String[] args) {
        //生成中奖号码
        int[] arr = createNumber();

        System.out.print("==============");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println("==============");
        //用户输入彩票号码
        int[] userArr = userInputNumber();
        /*for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }*/
       /* for (int i = 0; i < userArr.length; i++) {
            System.out.println(userArr[i]);
        }*/
        //2.用户输入彩票号码（红球+篮球）
        //3.判断用户的中奖情况
        //红球 蓝球

        int redCount = 0;
        int blueCount = 0;

        //判断红球
        for (int i = 0; i < userArr.length; i++) {
            int redNumber = userArr[i];
            for (int j = 0; j < arr.length - 1; j++) {
                if (redNumber == arr[j]) {
                    redCount++;
                    //计算红球中了的个数
                    break;
                }
            }
        }
        //判断蓝球
        int blueNumber = userArr[userArr.length - 1];
        if(blueNumber == arr[arr.length - 1]) {
            blueCount++;
        }
                //根据红球的个数以及蓝球的个数来判断中奖情况
                if (redCount == 6 && blueCount == 1){
                    System.out.println("恭喜你，中奖1000万");
                }else if( redCount == 6 && blueCount == 0){
                    System.out.println("恭喜你，中奖500万");
                }else if( redCount == 5 && blueCount == 1){
                    System.out.println("恭喜你，中奖3000");
                }else if(( redCount == 5 && blueCount == 0) || (redCount == 4 && blueCount == 1)){
                    System.out.println("恭喜你，中奖200元");
                }else if(( redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 1)){
                    System.out.println("恭喜你，中奖10元");
                }else if(( redCount == 2 && blueCount == 1) || (redCount == 1 && blueCount == 1) || (redCount == 0 && blueCount == 1)){
                    System.out.println("恭喜你，中奖5元");
                }else{
                    System.out.println("没有中奖，谢谢回顾");
                }
            }

    public static int[] userInputNumber(){
        //创建数组用于添加用户购买的彩票号码
        //红球6个 蓝球1个
        int[] arr = new int[7];

        //利用键盘录入用户号码
        Scanner sc = new Scanner(System.in);
        //输入红球
        for (int i = 0; i < 6;i++){
            System.out.print("请输入第"+(i+1)+"红球号码");
            int redNumber = sc.nextInt();
            //红球不能重复
            if(redNumber >= 1 && redNumber <=33){
                //调用方法
                boolean flag = contains(arr, redNumber);
                if(!flag){
                    arr[i] = redNumber;
                }else{
                    System.out.println("当前红球号码已经存在，请重新输入");
                }
            }else{
                System.out.println("号码超出范围");
            }
        }
        //输入蓝球号码
        System.out.println("请输入蓝球号码");
        while(true) {
            int blueNumber = sc.nextInt();
            if (blueNumber >= 1 && blueNumber <= 16) {
                arr[arr.length - 1] = blueNumber;
                break;
            } else {
                System.out.println("输入的号码超出范围");
            }
        }
        return arr;
    }
    //随机生成号码
    public static int[] createNumber(){
        //1.创建数组用于添加中奖号码
        //6个红球 1个篮球
        int[] arr = new int[7];
        //2.随机生成号码
        //红球不可重复，篮球可以和红球重复
        Random r = new Random();
        for (int i = 0; i < 6; ) {
            int rednumber = r.nextInt(33)+1;
            boolean flag = contains(arr, rednumber);
            if (!flag) {
                arr[i] = rednumber;
                i++;
            }
        }
        //生成蓝球号码
        int bluenumber = r.nextInt(16)+1;
        arr[arr.length-1] = bluenumber;
        return arr;
    }
    //用于判断数组在数组中是否存在
    public static boolean contains(int[] arr, int number) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number) {
                return true;
            }
        }
        return false;
    }
}
